package com.stylefeng.guns.modular.hhtb.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.hhtb.model.Banks;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.hhtb.service.IBanksService;

/**
 * 银行卡管理控制器
 *
 * @author fengshuonan
 * @Date 2018-09-12 09:37:18
 */
@Controller
@RequestMapping("/banks")
public class BanksController extends BaseController {

    private String PREFIX = "/hhtb/banks/";

    @Autowired
    private IBanksService banksService;

    /**
     * 跳转到银行卡管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "banks.html";
    }

    /**
     * 跳转到添加银行卡管理
     */
    @RequestMapping("/banks_add")
    public String banksAdd() {
        return PREFIX + "banks_add.html";
    }

    /**
     * 跳转到修改银行卡管理
     */
    @RequestMapping("/banks_update/{banksId}")
    public String banksUpdate(@PathVariable Integer banksId, Model model) {
        Banks banks = banksService.selectById(banksId);
        model.addAttribute("item",banks);
        LogObjectHolder.me().set(banks);
        return PREFIX + "banks_edit.html";
    }

    /**
     * 获取银行卡管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return banksService.selectList(null);
    }

    /**
     * 新增银行卡管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Banks banks) {
        banksService.insert(banks);
        return SUCCESS_TIP;
    }

    /**
     * 删除银行卡管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer banksId) {
        banksService.deleteById(banksId);
        return SUCCESS_TIP;
    }

    /**
     * 修改银行卡管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Banks banks) {
        banksService.updateById(banks);
        return SUCCESS_TIP;
    }

    /**
     * 银行卡管理详情
     */
    @RequestMapping(value = "/detail/{banksId}")
    @ResponseBody
    public Object detail(@PathVariable("banksId") Integer banksId) {
        return banksService.selectById(banksId);
    }
}
